<!--  -->
<template>
  <div class="center-wrap">
    <div class="center-wrap-box">
    <div class="course-center-head">
      <div class="head-box w1200">
        <div class="face-img" @mouseover="handleChangeFace" @mouseout="handleOutFace">>
          <img :src="userInfo.avatar" class="face"/>
          <div class="face-hover" v-show="isShowFace">
            <img src="@/assets/home/face-hover.png" />
          </div>
        <a-upload
          name="file"
          :multiple="true"
          action="https://e-school.yixuepai100.com/api/common/uploadonline"
          :headers="headers"
          @change="handleChange"
        >
          <a-button></a-button>
        </a-upload>
        </div>
        <div class="head-box-l">
          <span>{{userInfo.username}}</span>
        </div>
        <div class="head-box-r" @click="handleMenu(1)">
          <span>编辑个人信息</span>
        </div>
      </div>
    </div>
    <div class="course-center-main">
      <div class="main-box w1200">
        <div class="main-box-l">
          <ul>
           <li @click="handleMenu(2)" :class="{active: curIndex === 2}" :data-s="curIndex">
              <img src="@/assets/home/my-course-normal.png" v-if="curIndex === 2" />
              <img src="@/assets/home/my-course-icon.png" v-else />
              我的课程
            </li>
            <!-- <li @click="handleMenu(3)" :class="{active: curIndex === 3}">
              <img src="@/assets/home/my-work-normal.png" v-if="curIndex === 3"/>
              <img src="@/assets/home/my-work-icon.png" v-else/>我的作业
            </li> -->
            <!-- <li @click="handleMenu(4)" :class="{active: curIndex === 4}">
              <img src="@/assets/home/my-date-normal.png" v-if="curIndex === 4"/>
              <img src="@/assets/home/my-date-icon.png" v-else/>学习日历
            </li> -->
        <!--    <li @click="handleMenu(5)" :class="{active: curIndex === 5}">
              <img src="@/assets/home/my-order-normal.png" v-if="curIndex === 5" />
              <img src="@/assets/home/my-order-icon.png" v-else/>我的订单
            </li> -->
            <!-- <li @click="handleMenu(6)" :class="{active: curIndex === 6}">
              <img src="@/assets/home/my-mess-normal.png" v-if="curIndex === 6"/>
              <img src="@/assets/home/my-mess-icon.png" v-else />消息中心
            </li> -->
            <li @click="handleMenu(1)" :class="{active: curIndex === 1}">
              <img src="@/assets/home/per-icon.png" v-if="curIndex === 1" class="per"/>
              <img src="@/assets/home/per-normal.png" v-else class="per"/>个人信息
            </li>
            <li @click="handleMenu(3)" :class="{active: curIndex === 3}">
              <img src="@/assets/home/per-icon.png" v-if="curIndex === 3" class="per"/>
              <img src="@/assets/home/per-normal.png" v-else class="per"/>联系我们
            </li>
          </ul>
        </div>
        <div class="main-box-r">
          <router-view  ref="routerChild"></router-view>
          <!-- <div class="main-content" v-show="isPerson">
            <div class="tab">
              <span v-for="(item,i) in tabArr1" :key="'person' + i" :class="{active: i === personTab}" @click="handleTab(i)" >{{item}}</span>
            </div>
            <info v-show="personTab === 0" />
            <account v-show="personTab === 1" />
            <safe v-show="personTab === 2" />
            </div> -->
          <!-- </div> -->
          <!--content1-->
          <!-- <div class="main-content" v-show="isCourse">
            <div class="tab-zb">
              <div class="tab-zb-l">
                <span v-for="(item,i) in confs.channel" :key="'channel' + i" :class="{active: i.replace('a','') === query.channel}" @click="handleTabCourse(i, 'channel')" >{{item}}</span>
              </div>
              <div class="tab-zb-r">
                <span v-for="(item,i) in confs.is_end" :key="'is_end' + i" :class="{on: i === query.is_end}" @click="setQuery('is_end', i)" >{{item}}</span>
              </div>
            </div>
            <all-class :courseTab="courseTab" ref="classList" @noneData="handleNone"/>
            <no-class v-if="isNone" />
          </div> -->
          <!--content2-->
          <!-- <div class="main-content" v-show="isWork">
            <my-work />
          </div> -->
          <!-- <div class="main-content" v-show="isDate">
            <study />
          </div> -->
          <!--content日历-->
        </div>
      </div>
    </div>
    </div>
    <div class="person-footer">
      <Footer></Footer>
    </div>
  </div>
</template>

<script>
import {
  Upload
} from "ant-design-vue";
import Footer from "@/components/layout/Footer"
import account from './account.vue'
import safe from './safe.vue'
import info from './info.vue'
import allClass from './allClass.vue'
import noClass from './noClass.vue'
import study from './study.vue'
import myWork from './myWork.vue'
import { mapState, mapMutations } from "vuex";
import mTypes from "@/store/mutationsTypes";
import {
  postForm,
} from "@/services";
function getBase64(img, callback) {
  const reader = new FileReader();
  reader.addEventListener('load', () => callback(reader.result));
  reader.readAsDataURL(img);
}
export default {
  components: {
    account,
    safe,
    info,
    'all-class': allClass,
    'no-class': noClass,
    'my-work': myWork,
    study,
    Footer,
    AUpload: Upload
  },
  data () {
    return {
      isShowFace: false,
      headers: {
        authorization: 'authorization-text'
      },
      curIndex: 1
      // path: '',
      // query: {isShowFace
      //   is_end: '0',
      //   channel: '',
      // },
      // confs: {
      //   channel: { 'a': '全部', '0a':'一对一', '1a': '小班课', '2a': '直播课', '3a': '录播课', '4a': '公开课' },
      //   is_end: {'0': '默认', '1': '已结束'}
      // },
      // tabArr1: ['个人信息', '账号安全', '账户绑定'],
      // tabArr2: ['全部', '一对一', '小班课', '直播课', '录播课'],
      // tabArr3: ['默认', '已结束'],
      // isPerson: true,
      // isCourse: false,
      // isWork: false,
      // isDate: false,
      // personTab: 0,
      // courseTab: 0,
      // courseIndex: 0,
      // isNone: false
    }
  },
  computed: {
    ...mapState({
      userInfo: state => state.userInfo
    })
  },
  watch: {
    $route (to, from) {
      console.log(to)
      console.log(from)
      if (to.name === from.name) {
        this.$router.go(0)
      }
    }
  },
  created () {
    let path = this.$route.name
    switch (path) {
      case 'personInfo':
        this.curIndex = 1
        break;
      case 'myMessage':
        this.curIndex = 6
        break;
      case 'course':
        this.curIndex = 2
        break;
      case 'myWork':
        this.curIndex = 3
        break;
      case 'study':
        this.curIndex = 4
        break;
      case 'myOrder':
        this.curIndex = 5
        break;
      default:
        this.curIndex = 2
    }
  },
  mounted() {
    // this.$refs.classList.setQuery(this.query)
  },
  methods: {
    ...mapMutations([mTypes.userInfo]),
    handleMenu (type) {
      this.curIndex = type
      if (type === 1) {
        this.path = '/person-center/personInfo'
        this.$router.push({
          path: '/person-center/personInfo'
        })
        this.$refs.routerChild.handleTab && this.$refs.routerChild.handleTab(0)
        console.log(this.$refs.mychild)
        // this.isPerson = true
        // this.isCourse = false
        // this.isWork = false
        // this.isDate = false
      } else if (type === 2) {
        console.log(this.userInfo);
        // if(this.userInfo.study_tag == 0){
          // this.$router.push({
          //   path: '/person-center/course'
          // })
        // }else{
          this.$router.push({
            path: '/person-center/courselist'
          })
        // }
        // this.isCourse = true
        // this.isPerson = false
        // this.isWork = false
        // this.isDate = false
      } else if (type === 3) {
        // this.$router.push({
        //   path: '/person-center/myWork'
        // })
        this.$router.push({
          path: '/person-center/showConnect'
        })
        // this.isWork = true
        // this.isPerson = false
        // this.isCourse = false
        // this.isDate = false
      } else if (type === 4) {
        this.$router.push({
          path: '/person-center/study'
        })
        // this.isDate = true
        // this.isPerson = false
        // this.isCourse = false
        // this.isWork = false
      } else if (type === 5) {
        this.$router.push({
          path: '/person-center/myOrder'
        })
      } else if (type === 6) {
        this.$router.push({
          path: '/person-center/myMessage'
        })
      }
    },
    handleChange (info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        getBase64(info.file.originFileObj, imageUrl => {
          this.userInfo.avatar = imageUrl
        })
        this.$message.success('头像上传成功')
      } else if (info.file.status === 'error') {
        this.$message.error('头像上传失败')
      }
    },
    handleChangeFace () {
      console.log(444)
      this.isShowFace = true
    },
    handleOutFace () {
      this.isShowFace = false
    }
    // handleTab (type) {
    //   this.personTab = type
    // },
    // handleTabCourse (type, qk) {
    //   type = type.replace('a','')
    //   this.courseTab = Number(type)
    //   this.setQuery(qk, type)
    // },
    // setQuery (key, val) {
    //   let query = {}
    //   query[key] = val
    //   this.query = Object.assign({}, this.query, query)
    //   this.$refs.classList.setQuery(this.query)
    // },
    // handleCourse (i) {
    //   this.courseIndex = i
    // },
    // handleNone (val) {
    //   this.isNone = val
    // }
  }
}
</script>
<style lang="less" scoped>
/* @import url(); 引入公共css类 */
ul {
  margin: 0;
  padding: 0;
}
.center-wrap {
  width: 100%;
  height: calc(100% - 150px);
  &-box {
    min-width: 1200px;
    min-height: calc(100vh - 150px);
  }
}
.course-center-head {
  width: 100%;
  height: 150px;
  background: #fff url("~assets/home/center-bg.png") no-repeat;
  background-size: 100% 100%;
}
.course-center {
  width: 100%;
  &-head {
    display: flex;
    height: 150px;
    // background: #2E2E2E;
    .head-box {
      position: relative;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .face-img {
        position: absolute;
        left:0;
        bottom: -35px;
        width: 120px;
        height: 120px;
        background: #eee;
        border-radius: 60px;
        border-radius: 60px;
        overflow: hidden;
        cursor: pointer;
        .face {
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: 100%;
          z-index: 2;
        }
        .face-hover {
          position: absolute;
          left: 0;
          top: 0;
          width: 120px;
          height: 120px;
          background: rgba(0,0,0,.5);
          z-index: 3;
          img {
            width: 44px;
            height: 44px;
            margin-left: 38px;
            margin-top: 38px;
          }
        }
      }
    .head-box-l {
      position: relative;
      span {
        font-size: 30px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        line-height: 72px;
        color: #fff;
        margin-left: 155px;
      }
    }
    .head-box-r {
      width: 135px;
      height: 40px;
      text-align: center;
      border: 1px solid #fff;
      border-radius: 25px;
      cursor: pointer;
      span {
        line-height: 38px;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
        padding-left: 1px;
      }
    }
  }
  &-main {
    width: 100%;
    min-height: calc(100vh - 300px);
    background: #fff;
    .main-box {
      display: flex;
      &-l {
        margin-top: 94px;
        margin-right: 56px;
        ul {
          .active {
            color: #fff;
            background: url('../../assets/home/menu-bg.png') no-repeat;
            background-size: 100% 100%;
          }
          li {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 144px;
            height: 50px;
            line-height: 50px;
            font-size: 16px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #93999F;
            cursor: pointer;
            img {
              margin-right: 10px;
            }
            &:nth-child(1) {
              img {
                width: 16px;
                height: 15px;
              }
            }
            &:nth-child(2) {
              img {
                width: 16px;
                height: 12px;
              }
            }
            &:nth-child(3) {
              img {
                width: 14px;
                height: 14px;
              }
            }
            &:nth-child(4) {
              img {
                width: 15px;
                height: 16px;
              }
            }
            &:nth-child(5) {
              img {
                width: 13px;
                height: 15px;
              }
            }
            &:nth-child(6) {
              img {
                width: 13px;
                height: 16px;
              }
            }
          }
        }
      }
      &-r {
        flex: 1;
        margin-top: 50px;
        .main-content {
          .tab-zb {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid #C1C1C1;
            &-l {
              padding-left: 20px;
            }
            &-r {
              display: flex;
              align-items: center;
              .on {
                background-color: #27BFA3;
                color: #fff;
              }
              span {
                display: block;
                width: 60px;
                height: 29px;
                line-height:29px;
                color: #27BFA3;
                text-align: center;
                border: 1px solid #27BFA3;
                border-radius: 0 6px 6px 0;
                cursor: pointer;
                &:first-child {
                  border-radius: 6px 0 0 6px;
                }
              }
            }
          }
          .tab {
            border-bottom: 1px solid #C1C1C1;
          }
          .tab,.tab-zb-l {
            display: flex;
            align-items: center;
            .active {
              position: relative;
              color: #07997F;
              &::after {
                display: block;
                content: '';
                position: absolute;
                left: 50%;
                transform: translateX(-50%);
                bottom: -1px;
                width: 30px;
                height: 2px;
                background: #07997F;
              }
            }
            span {
              display: block;
              font-size: 16px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              line-height: 48px;
              color: #333333;
              margin-right: 40px;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
  &-foot {
    // position: fixed;
    // left: 0;
    // bottom: 0;
    display: flex;
    width: 100%;
    background: #fff;
    text-align: center;
    padding-bottom: 20px;
    .foot {
      span {
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        line-height: 24px;
        color: #8B95A0;
        padding-left: 26px;
        padding-right: 27px;
      }
    }
    .copy {
      padding-top: 13px;
      span {
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        line-height: 19px;
        color: #9EA6B0;
        padding-left: 7px;
        padding-right: 8px;
      }
    }
  }
}
/deep/.ant-upload {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 120px;
  height: 120px;
  border: none;
  opacity: 0;
  z-index: 100;
  .ant-btn {
    width: 120px;
    height: 120px;
  }
}
/deep/.ant-upload-list {
  display: none;
}
.person-footer {
  margin-top: 80px;
}
</style>
